package com.tripupdater.view
{
	import com.tripupdater.controller.Controller;
	import com.tripupdater.event.TUEvent;
	import com.tripupdater.event.TUEventDispatcher;
	import com.tripupdater.model.Model;
	import com.tripupdater.type.CommandType;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.system.Security;
	
	public class TripUpdaterMainView extends MovieClip
	{
		private var controller:Controller;
		private var evtDsp:TUEventDispatcher;
		private var model:Model;
		
		/*
		private var calendarView:CalendarView;
		private var facebookView:FacebookView;
		private var twitterView:TwitterView;
		*/
		private var sobres:MovieClip;
		
		private var twitterView:TwitterView;
		private var calendarView:CalendarView;
		private var mapView:MapView;
		private var skypeView:SkypeView;
		
		public function TripUpdaterMainView()
		{
			Security.allowDomain("*");
			
			stage.stageFocusRect= false;
			evtDsp= TUEventDispatcher.getInstance();
			controller= new Controller(evtDsp);

			model= Model.getInstance();
						
			addEventListener(Event.ADDED_TO_STAGE, createChildren);
		}
		
		private function createChildren(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, createChildren);
			
			sobres= getChildByName("sobresInstance") as MovieClip;
			
			twitterView= getChildByName("twitterInstance") as TwitterView;
			calendarView= getChildByName("calendarInstance") as CalendarView;
			mapView= getChildByName("mapInstance") as MapView;
			skypeView= getChildByName("skypeInstance") as SkypeView;
			
			sobres.mouseChildren= false;
			sobres.mouseEnabled= false;
			
			evtDsp.dispatchEvent(new TUEvent(CommandType.LOAD_APP_DATA, {twitterView: twitterView, mapView: mapView, skypeView: skypeView}, this));
			
			twitterView.visible= false;
			mapView.visible= false;
			skypeView.visible= false;
		}
		
		public function onReady():void
		{
		}
		
		public function onFacebookResult():void
		{
			trace(model.facebookData);
			//addChild(facebookView);
		}
	}
}